/**
 * 说明：
 * 创建人：pluto
 * 创建时间：2018/9/6
 */

var BusinessCtrl = function ($scope,AuthService,$uibModal) {
    $scope.result = {};
    $scope.param = {pageNum: 1, pageSize: 10, authStatus: 1, userType: 1};


    var loadData = function (param) {
        AuthService.list(param).then(function (res) {
            $scope.result = res;
        });
    };


    $scope.onPageChange = function () {
        $scope.param.pageNum = $scope.result.page.currentNo;
        loadData($scope.param);
    };
    $scope.toAudit = function (data) {
        var modalInstance = $uibModal.open({
            templateUrl: 'pages/auth/view/business-detail.html',
            controller: 'BusinessAuditCtrl',
            backdrop: "audit",
            size: 'lg',
            resolve: {
                data: function () {
                    return data;
                }
            }
        });

        modalInstance.result.then(function (selectedItem) {
            $scope.param.pageNum = 1;
            loadData($scope.param);
        }, function (aaa) {
            $log.info('Modal cancel at: ' + aaa + "," + new Date());
        });
    };
    $scope.$watch('$viewContentLoaded', function(){
        loadData($scope.param);
    });
};

var BusinessAuditCtrl = function ($scope, $uibModalInstance, data,AuthService) {
    $scope.user = angular.copy(data);
    $scope.confirm = function () {
        ListService.list();
        $uibModalInstance.close("confirm");
    };
    $scope.close = function () {
        $uibModalInstance.dismiss("cancel");
    };

    $scope.doAudit = function () {
        $scope.audit.userId = $scope.user.id;
        AuthService.authAudit($scope.audit).then(function () {
            layer.msg('审核成功',{icon: 1}) ;
            $uibModalInstance.close("confirm");
        },function (error) {
            layer.msg('审核失败',{icon: 2}) ;
        });
    }
};
angular.module('app.auth.business.controller',[])
    .controller("BusinessCtrl", BusinessCtrl)
    .controller('BusinessAuditCtrl', BusinessAuditCtrl);

